import router from './router/index'
import store from './store/index'
import NProgress from 'nprogress' // 引入一份进度条插件
import 'nprogress/nprogress.css' // 引入进度条样式
const go = ['/login', '/404']
router.beforeEach(async(to, from, next) => {
  NProgress.start()
  //   console.log(store.state.user.token)
  if (store.state.user.token) {
    if (to.path === '/login') { next() } else {
      if (!store.state.user.userinfo.userId) { await store.dispatch('user/asyncUserInfo') }
      next()
    }
  } else {
    if (go.includes(to.path)) { next() } else {
      next('/login')
    }
  }
  NProgress.done()
})

